package cn.springstudio.springui.extension;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

import com.contrarywind.adapter.WheelAdapter;
import com.github.gzuliyujiang.wheelpicker.contract.LinkageProvider;

import java.util.Arrays;
import java.util.List;

import cn.springstudio.springui.R;
import cn.springstudio.springui.databinding.ActivityWheelPickerBinding;

public class WheelPickerActivity extends AppCompatActivity {

    ActivityWheelPickerBinding binding;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = ActivityWheelPickerBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());

        binding.loopView.setItems(Arrays.asList("LoopView1", "LoopView2", "LoopView3", "LoopView4", "LoopView5"));
        binding.wheelView.setAdapter(new WheelAdapter() {
            @Override
            public int getItemsCount() {
                return 100;
            }

            @Override
            public Object getItem(int index) {
                return String.format("WheelView%03d", index + 1);
            }

            @Override
            public int indexOf(Object o) {
                return 0;
            }
        });

        binding.wheelView2.setData(Arrays.asList("WheelView1", "WheelView2", "WheelView3", "WheelView4", "WheelView5"));
        binding.numberWheelView.setRange(1,100,1);
        binding.optionWheelLayout.setData(Arrays.asList("OptionWheelLayout1", "OptionWheelLayout2", "OptionWheelLayout3",
                "OptionWheelLayout4", "OptionWheelLayout5"));
        binding.linkageWheelLayout.setData(new LinkageProvider() {
            @Override
            public boolean firstLevelVisible() {
                return true;
            }

            @Override
            public boolean thirdLevelVisible() {
                return false;
            }

            @NonNull
            @Override
            public List<?> provideFirstData() {
                return Arrays.asList("LinkageWheelLayout1", "LinkageWheelLayout2", "LinkageWheelLayout3",
                        "LinkageWheelLayout4", "LinkageWheelLayout5");
            }

            @NonNull
            @Override
            public List<?> linkageSecondData(int firstIndex) {
                return Arrays.asList(String.format("LinkageWheelLayout%d-1", firstIndex + 1),
                        String.format("LinkageWheelLayout%d-2", firstIndex + 1),
                        String.format("LinkageWheelLayout%d-3", firstIndex + 1),
                        String.format("LinkageWheelLayout%d-4", firstIndex + 1),
                        String.format("LinkageWheelLayout%d-5", firstIndex + 1));
            }

            @NonNull
            @Override
            public List<?> linkageThirdData(int firstIndex, int secondIndex) {
                return Arrays.asList(String.format("LinkageWheelLayout%d-%d-1", firstIndex + 1, secondIndex + 1),
                        String.format("LinkageWheelLayout%d-%d-2", firstIndex + 1, secondIndex + 1),
                        String.format("LinkageWheelLayout%d-%d-3", firstIndex + 1, secondIndex + 1),
                        String.format("LinkageWheelLayout%d-%d-4", firstIndex + 1, secondIndex + 1),
                        String.format("LinkageWheelLayout%d-%d-5", firstIndex + 1, secondIndex + 1));
            }

            @Override
            public int findFirstIndex(Object firstValue) {
                return 0;
            }

            @Override
            public int findSecondIndex(int firstIndex, Object secondValue) {
                return 0;
            }

            @Override
            public int findThirdIndex(int firstIndex, int secondIndex, Object thirdValue) {
                return 0;
            }
        });
    }
}